﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameEngine.Entities;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GameEngine.EntityComponents;
using PvT.EntityComponent;

namespace PvT.Entities
{
    public class Skynet : AbstractDrawableEntity
    {
        private bool isAnimation = false;
        /// <summary>
        /// Initializes a new instance of the <see cref="Skynet" /> class.
        /// </summary>
        /// <param name="components">The components.</param>
        /// <param name="isActive">if set to <c>true</c> [is active].</param>
        /// <param name="isVisible">if set to <c>true</c> [is visible].</param>
        /// <param name="position">The position.</param>
        /// <param name="game">The game.</param>
        public Skynet(List<IEntityComponent> components, bool isActive, bool isVisible, Vector2 position, Game game) :
            base(components, isActive, isVisible, position, game)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Skynet" /> class.
        /// </summary>
        /// <param name="components">The components.</param>
        /// <param name="isActive">if set to <c>true</c> [is active].</param>
        /// <param name="isVisible">if set to <c>true</c> [is visible].</param>
        /// <param name="position">The position.</param>
        /// <param name="game">The game.</param>
        /// <param name="isAnimation">if set to <c>true</c> [is animation].</param>
        public Skynet(List<IEntityComponent> components, bool isActive, bool isVisible, Vector2 position, Game game, bool isAnimation) :
            base(components, isActive, isVisible, position, game)
        {
            this.isAnimation = isAnimation;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is animation.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is animation; otherwise, <c>false</c>.
        /// </value>
        public bool IsAnimation
        {
            get
            {
                return isAnimation;
            }
            set
            {
                isAnimation = value;
            }
        }

        /// <summary>
        /// Loads the content.
        /// </summary>
        public override void LoadContent()
        {
            base.texture = game.Content.Load<Texture2D>("Enemy/skynet");
            this.components.Add(new SkynetComponent(this));
            this.scale = 0.4f;
            this.components.Add(new CollidableComponent(this, 0.0f));
        }

        /// <summary>
        /// Draws Skynet
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        /// <param name="gameTime">The game time.</param>
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (!isAnimation)
            {
                base.Draw(spriteBatch, gameTime);
            }
            else
            {
                DrawWithoutCamera(spriteBatch, gameTime);
            }
        }


        /// <summary>
        /// Draws the without camera.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        /// <param name="gameTime">The game time.</param>
        private void DrawWithoutCamera(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (!this.isVisible)
                return;
            spriteBatch.Begin();

            if (sourceRectangle == Rectangle.Empty)
                spriteBatch.Draw(texture, position, null, Color.White, rotation, origin, scale, effects, layerDepth);
            else
                spriteBatch.Draw(texture, position, sourceRectangle, Color.White, rotation, origin, scale, effects, layerDepth);

            spriteBatch.End();
        }
    }
}
